<?php
header("Content-Type: text/html; charset=utf8");
 
if(!isset($_POST['submit'])){
    exit("错误执行");
}//判断是否有submit操作
 
$name=$_POST['name'];//post获取表单里的name
$pwd = sha1($_POST['password']);//post获取表单里的password
 
include('conn.php');//链接数据库



$sql="insert into user(id,username,password) values (null,'$name','$pwd')";//向数据库插入表单传来的值的sql
$stmt = $pdo->prepare($sql);
$stmt->execute();
$stmt->fetch(PDO::FETCH_BOUND);
if (!$stmt){
    die('Error: ' . $stmt->getMessage());//如果sql执行失败输出错误
}else{
    echo "注册成功";//成功输出注册成功
}
 
$pdo = null;//关闭数据库
?>